<?php

namespace JsonLowCode\UI;

use JsonLowCode\UI\Traits\HasModel;
use JsonLowCode\Traits\Props\HasDisabled;
use JsonLowCode\Traits\Props\HasInline;
use JsonLowCode\Traits\Props\HasLabelDetail;
use JsonLowCode\Traits\Props\HasName;
use JsonLowCode\Traits\Props\HasRequireMarkPlacement;
use JsonLowCode\Traits\Props\HasShowFeedback;
use JsonLowCode\Traits\Props\HasShowLabel;
use JsonLowCode\Traits\Props\HasShowRequireMark;
use JsonLowCode\Traits\Props\HasSize;
use JsonLowCode\Traits\Slots\HasSlotFooter;
use JsonLowCode\Traits\Slots\HasSlotHeader;

/**
 * AppForm组件
 * @method static AppForm make(mixed $children = null) AppForm组件
 */
class AppForm extends Form
{
    protected string $componentName = "AppForm";

    use HasSlotHeader, HasSlotFooter;
    use HasDisabled, HasName, HasLabelDetail, HasShowLabel, HasInline, HasSize;
    use HasShowFeedback, HasShowRequireMark, HasRequireMarkPlacement;
    use HasModel;

    /**
     * @param mixed|null $children
     */
    public function __construct(mixed $children = null)
    {
        parent::__construct();
        $this->prop("messages",['required'=>'此字段不能为空!']);
        $this->children($children);
    }

    /**
     * @param string $type
     * @return $this
     */
    public function type(string $type = 'page' | 'modal' | 'drawer'): static
    {
        return $this->prop('type',$type);
    }

    /**
     * @param string $modalKey
     * @return $this
     */
    public function modalKey(string $modalKey): static
    {
        return $this->prop('modal-key',$modalKey);
    }

    /**
     * @param string|array $modalProps
     * @return $this
     */
    public function modalProps(string|array $modalProps = []): static
    {
        return $this->prop('modal-props',$modalProps);
    }

    /**
     * @param string $drawerKey
     * @return $this
     */
    public function drawerKey(string $drawerKey): static
    {
        return $this->prop('drawer-key',$drawerKey);
    }

    /**
     * @param string|array $drawerProps
     * @return $this
     */
    public function drawerProps(string|array $drawerProps = []): static
    {
        return $this->prop('drawer-props',$drawerProps);
    }


    /**
     * 表格的工具
     * @param string|array $toolbars {leftShow: true,rightShow: true}
     * @return $this
     */
    public function toolbars(string|array $toolbars): static
    {
        return $this->prop('toolbars',$toolbars);
    }


    /**
     * 表格的远程请求url
     * @param string $apiUrl
     * @return $this
     */
    public function apiUrl(string $apiUrl): static
    {
        return $this->prop('apiUrl',$apiUrl);
    }

    /**
     * async-validator 的默认验证信息
     * @param string|array $validateMessages
     * @return $this
     */
    public function validateMessages(string|array $validateMessages): static
    {
        return $this->prop('validate-messages',$validateMessages);
    }

}
